﻿using SuperSocket.Facility.Protocol;
using SuperSocket.SocketBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace gegateway
{
    class GatewayReceiveFilter : FixedHeaderReceiveFilter<BinaryRequestInfo>
    {
        public GatewayReceiveFilter():base(6)//头长度为6
        {

        }

        protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
        {
            Console.WriteLine("GetBodyLengthFromHeader start:" + Thread.CurrentThread.ManagedThreadId);
            int len = header[offset + 4] * 256 + header[offset + 5];
            return len;
        }

        protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header, byte[] bodyBuffer, int offset, int length)
        {
            Console.WriteLine("ResolveRequestInfo start:" + Thread.CurrentThread.ManagedThreadId);
            byte[] bodydata = new byte[length];
            Array.Copy(bodyBuffer, offset, bodydata, 0, length);
            return new BinaryRequestInfo(header.Array[header.Offset + 3].ToString("X"), bodydata);         
        }
    }
}
